package com.peanut.mapper;

import com.orm.annotation.Select;
import com.orm.annotation.Update;
import com.orm.mapper.BaseMapper;
import com.peanut.entity.AdminUser;
import com.peanut.entity.dto.MyInfo;
import com.spring.annotation.Service;

import java.util.List;

public interface AdminUserMapper extends BaseMapper<AdminUser> {
	
	// 登录验证
	@Select("select * from admin_user where user_name = #{userName} and password = #{password}")
	AdminUser login(String userName, String password);
	
	
	// 分页查询管理员，没有其他条件
	@Select("select * from admin_user limit #{offset},#{length}")
	List<AdminUser> pageQuery(int offset, int length);
	
	
	// 查询是否存在某个角色
	@Select("select count(1) from admin_user where role_id = #{roleId}")
	int queryCountByRoleId(int roleId);
	
	
	// 查询个人信息
	@Select("select nick_name,avatar_url from admin_user where id = #{id}")
	MyInfo queryMyInfo(int id);
	
	// 修改个人信息
	@Update("update admin_user set nick_name = #{myInfo.nickName} , avatar_url = #{myInfo.avatarUrl} where id = #{id}")
	int updateMyInfo(MyInfo myInfo, int id);
	
	// 修改个人密码
	@Update("update admin_user  set password = #{password} where id = #{id}")
	int updateMyPassword(String password,int id);
}
